@page "/admin/dept"
@using NetCorePal.D3Shop.Web.Admin.Client.Extensions
@using NetCorePal.D3Shop.Web.Admin.Client.Components.Identity.Dept


@attribute [ClientPermission(PermissionCodes.AdminUserManagement)]

<Table
    TItem="DepartmentResponse"
    @ref="_table"
    DataSource="_pagedDepartments"
    Total="_totalDepartments"
    @bind-PageIndex="_pageIndex"
    @bind-PageSize="_totalDepartments"
    OnChange="Table_OnChange"
    Loading="_loading">
    <PaginationTemplate>
        <Pagination Class="@context.PaginationClass"
                    Total="_totalDepartments"
                    PageSize="_totalDepartments"
                    Current="_pageIndex"
                    ShowSizeChanger
                    OnChange="context.HandlePageChange"/>
    </PaginationTemplate>
    <TitleTemplate>
        <GridRow Gutter="8" Justify="space-between">
            <GridCol Span="4">
                <Title Level="3">部门列表</Title>
            </GridCol>
            <GridCol Span="8" Offset="10">
                <Search Placeholder="搜索名称" @bind-Value="_departmentQueryRequest.Name" OnSearch="() => OnSearch()"/>
            </GridCol>
            <GridCol Span="2">
                <AuthorizeView>
                    @if (context.CheckPermission(PermissionCodes.DepartmentCreate))
                    {
                        <AddDept OnItemAdded="HandleItemAdded"></AddDept>
                    }
                </AuthorizeView>
            </GridCol>
        </GridRow>
    </TitleTemplate>
    <ColumnDefinitions Context="row">
        <PropertyColumn Title="名称" Property="c => c.Name"/>
        <PropertyColumn Title="描述" Property="c => c.Remark" />
        <ActionColumn Title="操作">
            <AuthorizeView>
                @if (context.CheckPermission(PermissionCodes.DepartmentEdit))
                {
                    <CascadingValue Value="@row">
                        <EditDeptInfo OnRowUpdated="HandleItemUpdated"></EditDeptInfo>
                    </CascadingValue>
                }
            </AuthorizeView>
       
            <AuthorizeView>
                @if (context.CheckPermission(PermissionCodes.DepartmentDelete))
                {
                    <a @onclick="() => Delete(row)">删除</a>
                }
            </AuthorizeView>
        </ActionColumn>
    </ColumnDefinitions>
</Table> 